import { _uploadObject } from '@/api/oss'

export class OssUtils {
	public static uploadCameraImage(file: Blob, UID: string) {
		return new Promise((resolve) => {
			let objectName = `${UID}.png`
			this.uploadObject(file, 'camera-images', objectName).then((data: any) => {
				resolve(data.UpInfo.Key)
			})
		})
	}

	public static uploadScreenImage(file: Blob, UID: string) {
		return new Promise((resolve) => {
			let objectName = `${UID}.png`
			this.uploadObject(file, 'screen-images', objectName).then((data: any) => {
				resolve(data.UpInfo.Key)
			})
		})
	}

	public static uploadObject(file: File | Blob, bucketName: string, objectName: string) {
		let formData = new FormData()
		formData.append('File', file as Blob)
		formData.append('BucketName', bucketName)
		if (objectName != '') formData.append('ObjectName', objectName)
		return new Promise((resolve) => {
			_uploadObject(formData)
				.then((data: any) => {
					resolve(data)
				})
				.catch((err: any) => {
					console.log(err)
				})
		})
	}
}
